package com.baizhi.action;

import com.baizhi.entity.User;
import com.baizhi.service.UserService;
import com.baizhi.service.impl.UserServiceImpl;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;

public class UserAction extends ActionSupport {
    //接收数据
    private String name;
    private String password;

    //服务方法
    public String login(){
        //调用业务
        UserService us = new UserServiceImpl();
        User user = us.login(name,password);
        if(user !=null ){
            //登录成功
            ServletActionContext.getRequest().getSession().setAttribute("user",user);
            return "success";
        }else{
            //登录失败
            return "error";
        }
    }
    public String logout(){
        ServletActionContext.getRequest().getSession().invalidate();
        return "success";
    }



    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}
